package com.xiaoxiong.mami.dao.mapperImpl;

import com.xiaoxiong.mami.dao.daomain.UserInfo;
import com.xiaoxiong.mami.dao.mapper.UserInfoMapper;
import org.apache.ibatis.annotations.*;
import org.apache.ibatis.type.JdbcType;

@Mapper
public interface UserInfoMapperImpl extends UserInfoMapper {

    @Select("select * from user_info where userId = #{userId} limit 1")
    UserInfo selectByUserId(String userId);


    @Select("select * from user_info where telephone = #{telephone}  limit 1")
    UserInfo selectByTelephone(String telephone);

    @Select("select * from user_info where telephone = #{telephone} and password=#{password} limit 1")
    UserInfo selectByTelephoneAndPassword(@Param("telephone") String telephone,@Param("password")String password);

    @Update(
            "update user_info set userName = #{userName}, " +
                    "telephone = #{telephone}, " +
                    "sex = #{sex}, " +
                    "headerUrl = #{headerUrl} " +
                    "where userId = #{userId}"
    )
    int updateByUserId(UserInfo userInfo);


    @Insert({
            "insert into user_info ( userId, ",
            "userName, telephone, ",
            "sex, headerUrl, ",
            "createTime, updateTime, ",
            "channel)",
            "values (#{userId,jdbcType=VARCHAR}, ",
            "#{userName,jdbcType=VARCHAR}, #{telephone,jdbcType=VARCHAR}, ",
            "#{sex,jdbcType=VARCHAR}, #{headerUrl,jdbcType=VARCHAR}, ",
            "now(),now(), ",
            "'XIAOCHENGXU')"
    })
    int insertUserInfo(UserInfo record);

}